<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Classify from "./../classify/index";
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {
    SelectImageCheckbox: async () =>
      Vue.extend(
        await Vue.prototype.$vFN.Components.Base.SelectImageCheckbox()
      ),
    SelectImageRadio: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImageRadio()),
    SelectAddressMap: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectAddressMap()),
  },
  data() {
    return {
      appWindow: window,
      form: {},

      // selectGoodsValue: "",
      // 加载
      load: true,
      item: "",
    };
  },
  methods: {
    // 选择分类相关
    async selectClass() {
      let res = await this.$vFN.Http.post(
        {
          url: "store/category/index",
        },
        this.appWindow
      );
      res.data.list.forEach((item) => {
        if (this.form.category_id == item.id) {
          this.item = item.name;
        }
      });
    },

    selectAddressMap() {
      this.$vFN.Directives.SelectAddressMap({
        appWindow: this.appWindow,
        apiConfig: this.$vFN.Tools.getAppGlobalData('componentsApiConfig.SelectDataGoods',this.appWindow),
        onSuccess: (res) => {
          // this.form.longitude = res.data.lat;
          // this.form.latitude = res.data.lng;
          // this.form.address = res.data.detailAddress;

          // this.form.city_id = res.data.cityCode;
          // this.form.province_id = res.data.provinceCode;
          // this.form.district_id = res.data.regionCode;

          this.form.city = res.data.city;
          this.form.province = res.data.province;
          this.form.district = res.data.region;
        },
      });
    },
    classify() {
      Classify.init({
        onSuccess: (res) => {
          this.form.category_id = res.id;
          this.item = res.name;
        },
      });
    },
    async getData() {
      let res = await this.$vFN.Http.post(
        {
          url: "store/setting/detail",
        },
        window
      );
      this.form = res.data;
      this.selectClass();
      if (res._ok) {
        this.load = false;
      }
    },
    async init() {
      this.getData();
    },
    async sum() {
      this.load = true;
      let res = await this.$vFN.Http.post(
        {
          url: "store/setting/base",
          data: this.form,
        },
        window
      );
      if (res._ok) {
        this.$vFN.Tools.messageSuccess("操作成功");
        this.getData();
      }
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>